package com.iflytek.util;

import org.apache.commons.dbcp.BasicDataSource;/**
 * @Author qing
 * @Date 2022/3/15 15:59
 */

import javax.sql.DataSource;
import java.io.IOException;
import java.util.Properties;

/**
 * @author qingyunchen
 * @Description
 * @Date: 2022/3/15 15:59
 * @Version 1.0
 */
public class DbUtils{
    //根据db.properties文件构造DataSource对象并返回
    public static DataSource getDataSource() {
        BasicDataSource basicDataSource = new BasicDataSource();
        Properties properties = new Properties();
        try {
            properties.load(DbUtils.class.getClassLoader().getResourceAsStream("db.properties"));
        } catch (IOException e) {
            e.printStackTrace();
        }
        basicDataSource.setDriverClassName(properties.getProperty("drive"));
        basicDataSource.setUrl(properties.getProperty("url"));
        basicDataSource.setUsername(properties.getProperty("username"));
        basicDataSource.setPassword(properties.getProperty("password"));
        return  basicDataSource;

    }
}